<script >
import axios from "axios";
import {getUserInfoFromToken} from "@/assets/js/TokenFunction";

export default {
  data(){
    return{
      tableData:[],
      currentPage: '1', //当前页 刷新后默认显示第一页
      pageSize: '2', //每一页显示的数据量 此处每页显示6条数据
    }
  },
  mounted() {
    this.getHis()
  },
  methods:{
    getHis(){
      axios.post("/hkgapi/chat/getChatHisByUID",{
        userId:getUserInfoFromToken("userId")
      }).then(res=>{
        this.tableData=res.data
      })
    },
    //点击按钮切换页面
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage; //每次点击分页按钮，当前页发生变化
      // console.log(this.currentPage);
    },
  }
}
</script>

<template>
<div>
  <el-table

      :data="tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
      style="width: 100%">
    <el-table-column
        prop="userMsg"
        label="用户对话"
        >
    </el-table-column>
    <el-table-column
        prop="botMsg"
        label="AI回答"
    >
    </el-table-column>
    <el-table-column
        prop="createTime"
        label="对话时间"
    >
    </el-table-column>
  </el-table>
  <!--分页按钮-->
  <el-pagination
      background

      layout="prev, pager, next,jumper, ->, total"
      :total="tableData.length"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-size="pageSize"

      style="text-align: center;margin-top: 15px">
  </el-pagination>
</div>
</template>

<style scoped>

</style>